home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 75 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: terris@rahul.net (Terris Linenbach)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
  4. Subject: Re: STL loops through a list with one element more than once!  Why?
  5. Date: 1 Jan 1996 17:48:13 -0000
  6. Organization: a2i network
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4c96ot$1ve@netlab.cs.rpi.edu>
  10. References: <4c1n8o$2jn@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12.  
  13. X-Original-Date: 1 Jan 1996 05:46:03 GMT
  14.  
  15. "erase" invalidates all active iterators on the container.  The results are 
  16. undefined.
  17.  
  18. Do this instead:
  19.  
  20. _itemList.erase( _itemList.begin(), _itemList.end() );
  21.  
  22.  
  23. - Terris
  24.  
  25. In article <4c1n8o$2jn@netlab.cs.rpi.edu>, wiseb@cs.rpi.edu says...
  26. >
  27. >X-Original-Date: Fri, 29 Dec 1995 16:21:37 -0800
  28. >
  29. >Hi,
  30. >
  31. >I am using the STL to hold a list of items for a DDEML topic.  When
  32. >the topic is destroyed, all of the associated items with that
  33. >topic are erased from the topic's item list.  Erasing the item
  34. >also causes the item's destructor to be called:
  35. >
  36. >
  37. >BOOL DDETopic::DelAllItems ()
  38. >{
  39. >#ifdef DEBUGON
  40. >Tracer t("DDETopic::DelAllItems ()");
  41. >#endif
  42. >
  43. >   for (_itemIter  =   _itemList.begin();
  44. >        _itemIter  !=  _itemList.end();
  45. >        _itemIter++)
  46. >   {
  47. >#ifdef DEBUGON
  48. >if (__theLog) __theLog->OutputLn ("calling erase for item");
  49. >#endif
  50. >      _itemList.erase (_itemIter);
  51. >   }
  52. >
  53. >   return TRUE;
  54. >}
  55. >
  56. >In my particular application the list only contains a single 
  57. >element.
  58. >
  59. >When DEBUGON is enabled, the single item is correctly deleted the
  60. >first time through the loop.  However, I can also verify that
  61. >the loop is entered a second time, thereby resulting in a GPF.
  62. >
  63. >Any ideas why the _itemIter != _itemList.end() test of the for
  64. >loop is failing?  Anyone else encountered this?
  65. >
  66. >Bowden
  67. >Dept of Computer Science, RPI
  68. >wiseb@cs.rpi.edu
  69. >http://www.cs.rpi.edu/~wiseb/
  70. >
  71. >    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  72. >    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  73. >    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  74. >    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  75.  
  76.  
  77.     [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  78.     [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  79.     [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  80.     [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  81.